package demo.screens
{
	import com.cheezeworld.screens.IScreenItem;
	import com.cheezeworld.screens.Root;
	import com.urbansquall.ginger.Animation;
	import com.urbansquall.ginger.AnimationPlayer;
	import com.urbansquall.ginger.tools.AnimationBuilder;
	import com.urbansquall.ginger.tools.AnimationPlayerFactory;
	
	import demo.BitmapDataLibrary;
	
	import flash.display.BitmapData;

	public class StressTestDemo extends DemoScreen
	{
		public function StressTestDemo(a_parentScreen:IScreenItem=null)
		{
			super(a_parentScreen);
			
			screenLabel = "Stress Test (2000 animations)";
			
			var bdLib:BitmapDataLibrary = new BitmapDataLibrary();
			var bd:BitmapData = bdLib.lookupBitmapData( BitmapDataLibrary.DOG_YELP_TS )
			
			// Create an animation using the AnimationBuilder class
			var dog:AnimationPlayer;
			dog = new AnimationPlayer();
			var animation:Animation = AnimationBuilder.importStrip( 12, bd, 60, 40, 4, 0, 0, 120, -30, -20 );
			animation.isLooping = true;
			dog.addAnimation( "yelp", animation);
			
			m_animationFactory = new AnimationPlayerFactory();
			m_animationFactory.register( "dog", dog );
			
			m_dogs = [];
			for( var i:int = 0; i < 2000; i++ )
			{
				dog = m_animationFactory.instantiate( "dog" );
				dog.x = Math.random() * Root.WIDTH;
				dog.y = 50 + Math.random() * (Root.HEIGHT - 125);
				m_dogs.push( dog );
				addChild( dog );
			}
		}
		
		public override function update(a_timePassed:int):void
		{
			var len:int = m_dogs.length;
			for( var i:int = 0; i < len; i++ )
			{
				m_dogs[ i ].update( a_timePassed );
			}
		}
		
		private var m_dogs:Array;
		private var m_animationFactory:AnimationPlayerFactory;
		
	}
}